/**
 * Created by Tuffy on 16/1/18.
 */
'use strict';

angular.module('starter.controllers')

.controller('HotelPriceAnalysisCtrl', ['$rootScope', '$scope', '$state', '$cordovaToast', '$ionicLoading', 'CrmHttp', function($rootScope, $scope, $state, $cordovaToast, $ionicLoading, CrmHttp) {
    /*var hotelId = $state.params.hotelId;
    $scope.hotelPriceAnalysis = {

    };*/

    $scope.hotelId = $state.params.hotelId;
    $scope.active = 0;
    /*$scope.form = {
        startTime: new Date().Format('yyyy-MM-dd'),
        endTime: Tools.addByTransDate(new Date().Format('yyyy-MM-dd'), 1)
    };*/
    $scope.getDistributionPriceList = [];

    // 标签切换
    $scope.onTabChange = function(index){
        $scope.active = index;
    };

    // 获取分销价格
    $scope.getDistributionPriceInfo = function() {
        $ionicLoading.show({
            template: '加载中...'
        });
        CrmHttp.get('/crm/crm-hotel-public/getDistributionPriceInfo?hotelId=' + $scope.hotelId)
            .then(function(resultData) {
                var res = resultData.data;
                if (res.success) {
                    $scope.getDistributionPriceList = res.attribute;
                } else {
                    $cordovaToast.showShortBottom(res.errorMsg);
                }
            }, function(error) {
                $cordovaToast.showShortBottom('获取分销数据错误');
            }).finally(function() {
            $ionicLoading.hide();
        });
    };

    angular.forEach($rootScope.EDIT_DATE.h_competitorList, function(item) {
        if (item.roomName === 'elong') {
            item.zhName = '艺龙';
        } else if (item.roomName === 'qunar') {
            item.zhName = '去哪儿';
        } else if (item.roomName === 'meituan') {
            item.zhName = '美团';
        } else if (item.roomName === 'ctrip') {
            item.zhName = '携程';
        } else if (item.roomName === 'switch') {
            item.zhName = '分销';
        }
    });
    $scope.hotelPriceAnalysis = $rootScope.EDIT_DATE.h_competitorList;

    // 销毁清楚数据
    /*$scope.$on('$destroy', function() {
        delete $rootScope.EDIT_DATE.h_competitorList;
    });*/

    $scope.getDistributionPriceInfo();

}]);